# from PyQt5.QtWidgets import QMainWindow,QApplication,QMessageBox,QLCDNumber
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from uiwin import Ui_Mainwin
from uiabout import Ui_aboutui
from PyQt5.QtCore import *
import sys


class child(QMainWindow, Ui_aboutui):
    def __init__(self):
        super(child, self).__init__()
        self.setupUi(self)

    def open(self):
        self.show()


class myform(QMainWindow, Ui_Mainwin):
    def __init__(self):
        super(myform, self).__init__()
        self.setupUi(self)
        self.initui()
        self.statbar()

    def initui(self):
        self.lcdNumber.display(55.66)
        self.actionnew.triggered.connect(self.action_save)
        self.actionopen.triggered.connect(self.action_open)
        #self.actionabout.triggered.connect(child.open())
        self.label.setText("4573959")


    def statbar(self):
        # 实例化状态栏
        self.statusBar = QStatusBar()
        self.statusBar_1 = QLabel('一号坑')
        self.statusBar_2 = QLabel('二号坑')
        self.statusBar_3 = QLabel('三号坑')
        self.statusBar_4 = QLabel('{:<40}'.format('四号坑'))

        self.statusBar.addWidget(self.statusBar_1, 1)
        self.statusBar.addWidget(self.statusBar_2, 1)
        self.statusBar.addWidget(self.statusBar_3, 1)
        self.statusBar.addWidget(self.statusBar_4, 1)
        self.statusBar.addWidget(self.statusBar_4, 1)
        self.setWindowTitle(sys.argv[0])

        # 设置状态栏，类似布局设置
        self.setStatusBar(self.statusBar)

    file_path = None

    def action_open(self):
        global file_path
        path = QFileDialog.getOpenFileName(window, "打开", "", "Image files(*.txt *.html *.jpg)")[0]
        if path:
            msg = QMessageBox()
            msg.setText(path)
            api = msg.exec_()
            self.textEdit.setText(open(path).read())
            file_path = path

    def action_save(self):
        if file_path is None:
            pass
        else:
            with open(file_path, "w") as f:
                f.write(self.textEdit.toPlainText())
            self.textEdit.document().setModified(False)

    def okButton_click(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Warning)  # 设置弹窗的QMessageBox.Icon类型
        msg.setWindowTitle('警告')  # 设置弹窗标题
        msg.setText("这是一个警告弹窗")  # 设置弹窗提示信息
        ok = msg.addButton('确认', QMessageBox.AcceptRole)  # 使用 addButton() 方法添加自定义按钮
        quit = msg.addButton('退出', QMessageBox.RejectRole)
        msg.setDefaultButton(quit)  # 设置默认按钮
        api = msg.exec_()  # 指定退出键；返回选中按钮的值
        if api == QMessageBox.AcceptRole:
            self.textEdit.setText("您选中了确认")
        elif api == QMessageBox.RejectRole:
            self.textEdit.setText("您选中了退出")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = myform()
    ch = child()
    window.show()
    window.saveButton.clicked.connect(ch.open)

    sys.exit(app.exec_())
